<%@ include file="/taglibs.jsp"%>

<title>Winter War Administration - User List</title>

<script type="text/javascript" language="javascript">
function confirmDelete(userID, registrations, events){
	if(confirm("Are you sure you want to delete this user? You will also be removing " + registrations + " registrations and " + events + " judged events!")){
		window.location.replace("user.do?method=delete&user.userID=" + userID);
	}
}
</script>

<button onclick="location.href='user.do?method=edit'">Add User</button>

<table class="list">
	<thead>
		<tr>
			<th><bean:message key="user.username"/></th>
			<th><bean:message key="user.firstName"/></th>
			<th><bean:message key="user.lastName"/></th>
			<th><bean:message key="user.created"/></th>
			<th>Is Judging?</th>
			<th>Has Registered?</th>
			<th></th>
		</tr>
	</thead>
	<tbody>
		<c:forEach var="user" items="${users}" varStatus="status">
			<c:choose>
				<c:when test="${status.count % 2 == 0}"><tr class="even"></c:when>
				<c:otherwise><tr class="odd"></c:otherwise>
			</c:choose>
				<td><a href="user.do?method=edit&amp;userID=${user.userID}">${user.username}</a></td>
				<td>${user.firstName}</td>
				<td>${user.lastName}</td>
				<td>${user.created }</td>
				<td>
					<c:choose>
						<c:when test="${user.submittedEventsSize > 0 }">Yes!</c:when>
						<c:otherwise>No!</c:otherwise>
					</c:choose>
				</td>
				<td>
					<c:choose>
						<c:when test="${user.registrationsSize > 0 }">Yes!</c:when>
						<c:otherwise>No!</c:otherwise>
					</c:choose>
				</td>
				<td><a href="javascript:void()" onClick="confirmDelete(${user.userID }, ${user.registrationsSize }, ${user.submittedEventsSize })">Remove</a></td>
			</tr>
		</c:forEach>
	</tbody>
</table>